const mongoose = require("mongoose");
//获取所有订单
module.exports.getAllforms3 = async function ({currentPage,pageSize}) {
    //获取所有订单（不包括删除，不分页）
    const allData =await mongoose.model("orderformModel").find({isSend:{$ne:"3"}}).populate("userId").populate("goodId")
    //获取所有订单（不包括删除，分页）
    const limitData =await mongoose.model("orderformModel").find({isSend:{$ne:"3"}})
    .populate("userId").populate("goodId").limit(pageSize-0).skip((currentPage-1)*pageSize)
    //获取所有订单条数（不包括删除）
    const allDataNumber =await mongoose.model("orderformModel").find({isSend:{$ne:"3"}}).countDocuments()
    return {limitData,allDataNumber,allData};
 }
//获取一个订单
module.exports.getOneforms3 = async function (reqData) {
    //关联
    const oneData =await mongoose.model("orderformModel").find(reqData).populate("userId").populate("goodId")
    //不关联
    const data =await mongoose.model("orderformModel").find(reqData)
    return {oneData,data}
 }
//限制订单获取条数
module.exports.getLimitforms3 = async function ({currentPage,pageSize,isSend}) {
    const limitData =await mongoose.model("orderformModel").find({isSend})
    .populate("userId").populate("goodId").limit(pageSize-0).skip((currentPage-1)*pageSize)
    const allDataNumber =await mongoose.model("orderformModel").find({isSend}).countDocuments()
    return {limitData,allDataNumber};
 }
//修改订单
module.exports.updateform3 = async function (reqData) {
    const _id = reqData._id
    const data =await mongoose.model("orderformModel").updateOne({_id},reqData)
    return data;
 }
//添加订单
module.exports.addform3 = async function (reqData) {
    const data =await mongoose.model("orderformModel").create(reqData)
    return data;
 }
